<template>
  <div>
    <go-top></go-top>
    <div class="index">

      <div class="main">
        <!-- 主体 -->
              <div class="search">
          <input type="text" v-model="Svalue" @keyup.enter="Search">
          <div class="" @click="Search">搜索</div>
        </div>
        <div class="message">
          <comment-model :Pdata="Pdata[0]" v-for="i in 10" :key="i" />
        </div>
        <div class="btn"><p class="more">加载更多++</p></div>
        <div></div>
      </div>
      <div class="alide">
        <!-- 二维码 -->
        <div class="QR">
          <img
            src="https://img-static.mihoyo.com/new_qrcode/qrcode_ys.png"
            alt=""
          />
          <div>
            <p>扫码下载米游社App</p>
            <p>了解提瓦特最新资讯</p>
          </div>
        </div>
        <div class="hostroy">
          <div class="title">
            <span>搜索历史</span>
            <span @click="clear">清空</span>
          </div>
          <ul v-if="SearchHistory">
            <li v-for="(n,i) in SearchHistory" :key="i" @click="GoHistoy(n)">{{n}}</li>
          </ul>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { Swiper, SwiperSlide } from "vue-awesome-swiper";
import "swiper/css/swiper.css";
import CommentModel from "@/components/CommentModel.vue";
import NavBar from "@/components/NavBar.vue";
import GoTop from '@/components/GoTop.vue';
export default {
  name: "swiper-example-pagination",
  title: "Pagination",
  components: {
    Swiper,
    SwiperSlide,
    CommentModel,
    NavBar,
    GoTop,
  },
  methods: {
    Search(){
      // if(!this.SValue) return
      console.log()
      if(this.$route.query.keyword==this.Svalue) return
      this.$store.commit('pushSearch',this.Svalue)
      this.SearchHistory = JSON.parse(sessionStorage.getItem('search'))
      this.$router.replace('/Search?keyword='+this.Svalue)
      // this.$router.push
    },
    GoHistoy(v){
      if(this.Svalue==v) return
      this.$router.push('/Search?keyword='+v)
      this.Svalue=v 
    },
    clear(){
      sessionStorage.removeItem('search')
      this.SearchHistory=null
      this.$store.state.Search=[]
    }
  },
  data() {
    return {
      Pdata: [
        {
          avatar: "https://img-static.mihoyo.com/avatar/avatar10014.png",
          userName: "西风快报员",
          userLevel: 12,
          dataTime: 1659403140000,
          class: "官方",
          module: "原神",
          title: "「焰色天河」祈愿：「琉焰华舞·宵宫(火)」概率UP！",
          article:
            "活动期间，旅行者可以在活动祈愿中获得更多角色与武器，组建强大的队伍！",
          images: [
            "https://upload-bbs.mihoyo.com/upload/2022/07/26/75276539/2508d400ba2e8494867e05259d04b6cd_4432750527329040643.jpg?x-oss-process=image//resize,s_600/quality,q_80/auto-orient,0/interlace,1/format,jpg",
            "https://upload-bbs.mihoyo.com/upload/2022/07/26/75276539/b715282d3609129d4f8ae178091286a1_3323430204500352293.png?x-oss-process=image//resize,s_600/quality,q_80/auto-orient,0/interlace,1/format,png",
          ],
          pageView: 300000,
          comment: 300000,
          like: 30000,
        },
      ],
      Svalue:this.$route.query.keyword,
      SearchHistory:null
    };
  },
  mounted () {
   this.SearchHistory=JSON.parse(sessionStorage.getItem('search'))
   console.log(this.$store.state.Search)
  },
};
</script>

<style scoped>
.index {
  display: flex;
  width: 65%;
  /* background: black; */
  margin: 0px auto 60px;
  padding-top: 30px;
  
}
.main {
  width: 640px;
  border-radius: 10px;
  /* padding: 20px 20px; */
  margin:0px 25px 0 auto;
}
.search{
  background: white;
  display: flex;
  justify-content: space-between;
  margin-top:66px;
  border-radius: 10px;
}
.search input{
  padding: 16px;
  font-size: 16px;
  outline: none;
  border: 0;
  border-radius:10px 0px 0px 10px;
}
.search div{
  user-select: none;
  background: #ffe14c;
  padding: 20px 60px;
  color: #663c0f;
  font-weight: 900;
  border-radius:0 10px 10px 0;
}
.message {
  margin-top: 20px;
  padding: 20px 20px;
    background: white;
  box-sizing: border-box;
  /* margin-top: 30px; */
  border-radius: 10px;
  width: 100%;
  background: #fff;
}
.btn {
  text-align: center;
}
.more {
  margin: 0 auto;
  width: 100px;
  padding: 20px;
  background: #1fbbf4;
  border-radius: 50px;
  color: white;
  margin-top: 10px;
}
.alide {
  margin-top: 66px;
  width: 280px;
  margin-right: auto;
}
.alide .QR {
  width: 260px;
  padding: 10px;
  background: #fff;
  display: inline-flex;
  justify-content: center;
  align-items: center;
}
.alide .QR img {
  width: 100px;
  margin-right: 5px;
}
.alide .QR > div > p:first-child {
  color: #1fbbf4;
}
.alide .hostroy{
  margin-top: 20px;
  background: #fff;
  border-radius: 10px;
  min-height: 300px;
}
.alide .hostroy .title{
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  border-bottom:1px #999 dashed;
  user-select: none;
}
.alide .hostroy .title span:nth-child(1){
  font-weight: 600;
}
.alide .hostroy .title span:nth-child(2){
  font-size: 14px;
  color: #999;
}
.alide .hostroy ul{
  padding: 20px;
  display: flex;
  flex-flow: row wrap;
  overflow: hidden;
}
.alide .hostroy ul li{
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0px 12px;
  border:1px solid #ebebeb;
  border-radius: 15px;
  font-size: 14px;
  line-height: 28px;
  margin-right: 12px;
  margin-bottom: 12px;
  user-select: none;
}
</style>  